package utils

import "fmt"

type FamilyAccount struct {
	flag       bool
	state      string
	hasDeposit bool
	//定义账户余额
	balance float64
	//每次收支的金额
	money float64
	//说明
	note string
	//收支详情
	detail   string
	userName string
	password string
}

func NewFamilyAccount() *FamilyAccount {
	return &FamilyAccount{
		flag:       true,
		state:      "",
		hasDeposit: false,
		balance:    10000.0,
		money:      0.0,
		note:       "",
		detail:     "收支\t账户金额\t\t收支金额\t\t说 明",
		userName:   "lds123456",
		password:   "1234567890",
	}
}
func (this *FamilyAccount) login(username string, password string) bool {
	if this.userName == username && this.password == password {
		fmt.Println("登录成功")
		return true
	} else {
		fmt.Println("用户名或密码不正确")
		return false
	}
}
func (this *FamilyAccount) GetDetails() {
	if this.hasDeposit == false {
		fmt.Println("您没有任何存取款记录")
	} else {
		fmt.Println("--------------当前收支明细记录--------------")
		fmt.Println(this.detail)
	}
}
func (this *FamilyAccount) IncomeRegistration() {
	fmt.Println("本次收入金额：")
	_, _ = fmt.Scanln(&this.money)
	this.balance += this.money
	fmt.Println("本次收入说明：")
	_, _ = fmt.Scanln(&this.note)
	this.detail += fmt.Sprintf("\n收入\t%v\t\t%v\t\t%v", this.balance, this.money, this.note)
	this.hasDeposit = true
}
func (this *FamilyAccount) ExpenseRegistration() {
	fmt.Println("登记支出")
	fmt.Println("请输入本次支出的金额")
	_, _ = fmt.Scanln(&this.money)
	if this.money < this.balance {
		this.balance -= this.money
	} else {
		fmt.Println("您的余额不足")
		return
	}
	fmt.Println("本次支出说明：")
	_, _ = fmt.Scanln(&this.note)
	this.detail += fmt.Sprintf("\n支出\t%v\t%v\t%v", this.balance, this.money, this.note)
	this.hasDeposit = true
}
func (this *FamilyAccount) Exit() {
	fmt.Println("确认要退出吗？y/n,按y退出，n继续")
	_, _ = fmt.Scanln(&this.state)
	if this.state == "y" {
		this.flag = false
	}
}
func (this *FamilyAccount) MainMenu() {
	userName := ""
	password := ""
	fmt.Println("请输入您的用户名")
	_, _ = fmt.Scanln(&userName)
	fmt.Println("请输入您的密码")
	_, _ = fmt.Scanln(&password)
	if this.login(userName, password) == true {
		var choice int8
		for {
			fmt.Println("--------------家庭收支记账软件--------------")
			fmt.Println("              1.收支明细                   ")
			fmt.Println("              2.收入登记                  ")
			fmt.Println("              3.支出登记                   ")
			fmt.Println("              4.退出                   ")
			fmt.Println("              请选择1-4                   ")
			_, _ = fmt.Scanln(&choice)
			switch choice {
			case 1:
				this.GetDetails()
			case 2:
				this.IncomeRegistration()
			case 3:
				this.ExpenseRegistration()
			case 4:
				this.Exit()
			default:
				fmt.Println("请输入正确选项")
			}
			if !this.flag {
				break
			}
		}
		fmt.Println("您已经成功退出")
	}

}

//客户管理系统
